package freespiritsocial.io.user.data.model

import androidx.collection.ArrayMap
import freespiritsocial.io.user.data.model.bean.PostPojo
import java.util.*

class UploadPostEvent(
    val postPojo: PostPojo,
    val id: String = UUID.randomUUID().toString(),
    @Volatile var status: String = PublishStart,
    var processMap: ArrayMap<String,Int> = ArrayMap(),
    var process: Int = 0
) {
    init {
        processMap.let { map ->
            postPojo.uploadFiles?.forEach {
                map[it.name] = 0
            }
        }
    }

    companion object {
        const val PublishStart = "PublishStart"
        const val PublishReStart = "PublishReStart"
        const val Publishing = "Publishing…"
        const val PublishCompete = "PublishCompete"
        const val PublishCancel = "PublishCancel"
        const val PublishFailed = "Publish Failed"
        const val PublishFinish = "Publish Finish"
    }

    val isFail get() = status == PublishFailed

    val processStr get() = "${process}%"
    override fun equals(other: Any?): Boolean {
        if (other !is UploadPostEvent) return false
        if (other.id == id) return true
        return super.equals(other)
    }

    override fun hashCode(): Int {
        return id.hashCode()
    }
}
